define(['../../../../../js/lib/other/sweet-alert'],function() {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','27');//显示底部文字
    	
    	//默认值
    	$scope.waitCnofirm = false,$scope.isslide_up = false,$scope.mainslide_down = false,$scope.isslide_down = false,$scope.isslide_left = false;
    	$scope.payAmt = "";
    	var waitConfirmRepay = new Array();
    	
    	
//    	document.querySelector("#showBottom .right").style.marginTop = document.querySelector("#showBottom .left").style.marginTop = (document.documentElement.clientHeight - 530) + 'px';
    	
    	if($routeParams.flag != "" && $routeParams.flag != null){
    		getRepayDetail($routeParams.flag);
    	}
    	
    	//点击我要还款
    	$scope.goRepay = function(){
    		$scope.isslide_up = true;
    		$scope.aliShow = true,$scope.weiShow = false,$scope.otherShow = false;
    		if(document.documentElement.clientHeight < 530){
    			document.querySelector("#showBottom .right").style.height = document.querySelector("#showBottom .left").style.height = '460px';
    			document.querySelector("#showBottom .right").style.marginTop = document.querySelector("#showBottom .left").style.marginTop = (document.documentElement.clientHeight - 460) + 'px';
    		}else{
    			document.querySelector("#showBottom .right").style.marginTop = document.querySelector("#showBottom .left").style.marginTop = (document.documentElement.clientHeight - 530) + 'px';
    		}
    		
    	}
    	
    	//点击确认支付
    	$scope.confirmPay = function(){
    		if($scope.payAmt != ""){
    			if($scope.otherShow){
    				$scope.$emit("promptAlertMsg","请选择另外两种支付方式");
    				$scope.$emit("showCollect",true);
    				$timeout(function(){
    					$scope.$emit("showCollect",false);
    				},transData.promptTime);
    				return;
    			}
    			//微信:'0',支付宝：'1','线下'：'2'
            	if($scope.aliShow){
            		getOrderId('1','');
    			}else if($scope.weiShow){
    				getOrderId('0','');
    			}
    		}else{
    			$scope.$emit("promptAlertMsg","请先输入还款金额");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    		}
    	}
    	
    	//点击知道了
    	$scope.knowGoPay = function(){
    		$scope.isslide_down = false;
            $scope.mainslide_down = false;
            $scope.isslide_up = false;
    	}
    	
    	//查看详情
    	$scope.checkDetail = function(data){
    		$scope.isslide_up = true;
    		$scope.mainslide_down = true;
    		$scope.isslide_down = true;
    		
    		$scope.payDate = data.repayDate;
    		$scope.payTypeName = "线下支付";
    		$scope.payMoney = data.repayAmount;
    	}
    	
    	//点击确认线下支付
    	$scope.confirmLine = function(){
    		var contentInfo = {};
    		contentInfo.repayMentType = "转账或汇款";
    		contentInfo.remitAmt = $scope.remitAmt;
    		contentInfo.remitName = $scope.remitName;
    		contentInfo.rmitDate = $scope.rmitDate;
			if(isNaN($scope.remitAmt)){
				$scope.$emit("promptAlertMsg","汇款金额格式不正确");
				$scope.$emit("showCollect",true);
				$timeout(function(){
					$scope.$emit("showCollect",false);
				},transData.promptTime);
				return;
			}else if(! $scope.remitName){
				$scope.$emit("promptAlertMsg","汇款姓名不能为空");
				$scope.$emit("showCollect",true);
				$timeout(function(){
					$scope.$emit("showCollect",false);
				},transData.promptTime);
				return;
			}else if(! $scope.rmitDate){
				$scope.$emit("promptAlertMsg","汇款时间不能为空");
				$scope.$emit("showCollect",true);
				$timeout(function(){
					$scope.$emit("showCollect",false);
				},transData.promptTime);
				return;
			}
			getOrderId('2',contentInfo);
    	}
    	
    	
    	//点击选择支付方式
    	$scope.selectPayMode = function(type){
    		if(type == "支付宝"){
    			$scope.aliShow = true;
    			$scope.weiShow = false;
    			$scope.otherShow = false;
    		}else if(type == "微信"){
    			$scope.aliShow = false;
    			$scope.weiShow = true;
    			$scope.otherShow = false;
    		}else if(type == "其它"){
    			//默认值
    			$timeout(function(){
        			$scope.remitAmt = "",$scope.remitName = "",$scope.rmitDate = "";
    			},0);
    			$scope.aliShow = false;
    			$scope.weiShow = false;
    			$scope.otherShow = true;
    			$scope.isslide_left = true;
    		}
    	}
    	
    	
    	//点击选择线下支付方式
//    	$scope.clickRepayType = function(type){
//    		if(type === "转账或汇款"){
//    			$scope.repayMentName = type;
//    			$scope.payInAmt = "",$scope.payInName = "",$scope.payInDate = "";
//    			$scope.isremitAmt = false,$scope.isremitName = false,$scope.isrmitDate = false,$scope.ispayInAmt = true,$scope.ispayInName = true,$scope.ispayInDate = true;
//    		}else if(type === "现金支付"){
//    			$scope.remitAmt = "",$scope.remitName = "",$scope.rmitDate = "";
//    			$scope.repayMentName = type;
//    			$scope.isremitAmt = true,$scope.isremitName = true,$scope.isrmitDate = true,$scope.ispayInAmt = false,$scope.ispayInName = false,$scope.ispayInDate = false;
//    		}
//    	}
    	

        //关闭免息贷还款
        $scope.closePayType = function(){
            $scope.isslide_up = false;
        }

        //点击关闭线下支付
        $scope.closeLine = function(){
            $scope.isslide_left = false;
        }

        //点击关闭知道了
        $scope.closeComInfo = function(){
            $scope.isslide_down = false;
            $scope.mainslide_down = false;
            $scope.isslide_up = false;
        }
        
      //支付宝支付
    	function alipay(){
    		var aliOrderInfo = {};
    		aliOrderInfo.outTradeNo = transData.orderId;
    		aliOrderInfo.totalFee = $scope.payAmt *1;
    		aliOrderInfo.subject = "赢火虫还款";
    		aliOrderInfo.body = "prd";
    		payPack.alipay(JSON.stringify(aliOrderInfo),function(ret){
	    			var tempData = JSON.parse(ret);
	    			if(tempData.code == '01'){
	    				sweetAlert("未检测到有效的支付宝账户", "请安装新版支付宝客户端","",function(){});
	    			}else if(tempData.code == '00'){
	    				$scope.$emit("goNext","/sucRepaying");
	    			}
    			},function(){});
    	}
    	
    	//微信支付
    	function wechatPay(){
    		var wechatOrderInfo = {};
    		wechatOrderInfo.outTradeNo = transData.orderId;
    		wechatOrderInfo.totalFee = $scope.payAmt *1;
    		wechatOrderInfo.subject = "赢火虫还款";
    		wechatOrderInfo.body = "prd";
    		payPack.wechat(JSON.stringify(wechatOrderInfo),function(ret){
    			var tempData = JSON.parse(ret);
    			if(tempData.code == '01'){
    				sweetAlert("未检测到有效的微信账户", "请安装新版微信客户端","",function(){});
    			}else if(tempData.code == '00'){
	    			$scope.$emit("goNext","/sucRepaying");
	    		}
    		},function(){});
    	}
    	
    	
    	//调用代理下订单
    	function getOrderId(type,content){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	if(type === '2'){
        		bizInfo.repayAmount = $scope.remitAmt *1;
        	}else{
        		bizInfo.repayAmount = $scope.payAmt *1;
        	}
        	
        	bizInfo.repayMode = type;
        	bizInfo.loanApplyId = $routeParams.flag;
        	bizInfo.memo = content;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("repay",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$timeout(function(){
							transData.orderId = tempData.body;
							$scope.$emit("loadingChange",false);
							//微信:'0',支付宝：'1','线下'：'2'
							if(type === '0'){
								wechatPay();
							}else if(type === '1'){
								alipay();
							}else if(type === '2'){
								$scope.$emit("goNext","/sucRepaying");
							}
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    				},transData.promptTime);
		    			}
		    		});
    	}

    	//调用代理接口获取数据
    	function getRepayDetail(flag){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.loanApplyId = flag;
    		$scope.$emit("loadingChangeNav",true);
    		bizProxy.queryProxyBizData("queryRepayRecord",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			if(tempData.body != "" && tempData.body != null && tempData.body != "[]"){
							$timeout(function(){
								$scope.$emit("loadingChangeNav",false);
								var myRepayData = JSON.parse(tempData.body);
								$scope.repayData = myRepayData;
								var repayDetailData = myRepayData.repayDetailList;
								if(repayDetailData != "" && repayDetailData != null && repayDetailData != '[]'){
									$scope.repayDetailList = repayDetailData;
									waitConfirmRepay = new Array();
									for(var i=0;i<repayDetailData.length;i++){
										if(repayDetailData[i].status == '0'){
											waitConfirmRepay.push(repayDetailData[i]);
										}
									}
									if(waitConfirmRepay.length > 0){
										$scope.waitConfirmList = waitConfirmRepay;
									}else{
										$scope.waitConfirmList = "";
									}
								}else{
									$scope.repayDetailList = "";
									$scope.waitConfirmList = "";
								}
							},0);
						}else{
							$scope.$emit("loadingChangeNav",false);
							$scope.$emit("promptAlertMsg","未查找到相关数据");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
						}
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChangeNav",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChangeNav', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    					history.back();
		    				},transData.promptTime);
		    			}
		    		});
    	}
        $scope.$apply();
    }];
});